import pandas as pd
import numpy as np
from sklearn.cross_validation import KFold
from sklearn.ensemble import ExtraTreesRegressor
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import mean_squared_error


seed = 1024

np.random.seed(seed)

path = '../data/'



train_x = pd.read_pickle(path + 'train_X.pkl')
valid_x = pd.read_pickle(path + 'valid_X.pkl')
dev_x = pd.read_pickle(path + 'dev_X.pkl')

train_y = pd.read_pickle(path+'train.pkl')['label']
valid_y = pd.read_pickle(path+'valid.pkl')['label']
dev_y = pd.read_pickle(path+'dev.pkl')['label']



rf_params = {
    'n_jobs': 16,
    'n_estimators': 250,
    'max_features': 0.5,
    'max_depth': 8,
    'min_samples_leaf': 2,

}


clf = RandomForestClassifier(**rf_params)

clf.fit(train_x,train_y)


y_pred = clf.predict(valid_x)

from sklearn.metrics import accuracy_score
y_v = (y_pred+0.5).astype(int)
acc =  accuracy_score(valid_y,y_v)

print('randomforest model the accuracy on the valid set is : {}%'.format(round(acc* 100,2)))

